<template>
  <el-main>
   <el-table
    :data="newslist"
    style="width: 100%"
    :row-class-name="tableRowClassName">
    <el-table-column
      prop="date"
      label="日期"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="120">
      <template slot-scope="scope">
        <el-button
          @click.native.prevent="deleteRow(scope.$index, newslist)"
          type="text"
          size="small">
          移除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</el-main>

</template>

<script>
export default {
  data () {
    return {
      newslist:[]
    }
  },
    created:function (){
    this.$axios.post('/news/index')
      //成功返回
      .then(response=>{
      	this.newslist = response.data.articles;
         console.log(response);
      })
      //失败返回
      .catch(error=>{
          console.log(error);
      })
 },methods: {
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        else if (rowIndex === 6) {
          return 'errow-row';
        }
        return '';
      },
       deleteRow(index, rows) {
        rows.splice(index, 1);
      }
    }
}
</script>
<style>
	.el-table .warning-row {
    background: oldlace;
  }

 .el-table .success-row {
    background: #f0f9eb;
  }
  .el-table .errow-row {
    background: #FAB6B6;
  }
</style>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}

</style>-->
